/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.jr2tecnologia.controller.dashboard;

import br.com.jr2tecnologia.ConstantsOfSystem;
import br.com.jr2tecnologia.LoggerFactory;
import br.com.jr2tecnologia.SMSMailUtil;
import br.com.jr2tecnologia.model.ConfigPersistenceLocal;
import br.com.jr2tecnologia.model.entity.Config;
import java.io.Serializable;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author ronildo
 */
@ManagedBean
@SessionScoped
public class EditConfigMBean implements Serializable{

    private static final Logger logger = LoggerFactory.getLogger();

    @EJB
    private ConfigPersistenceLocal configPersistence;

    private Config selectedConfig;

    public EditConfigMBean(){
        logger.info("Carregando EditConfigMBean");
        selectedConfig = new Config();
    }

    public Config getSelectedConfig() {
        logger.info("pegando um selectedConfig: " + selectedConfig != null ? selectedConfig.getName() : null);
        return selectedConfig;
    }

    public void setSelectedConfig(Config selectedConfig) {
        logger.info("setando um selectedConfig: " + selectedConfig != null ? selectedConfig.getName() : null);
        this.selectedConfig = selectedConfig;
    }

    public void update(){
        configPersistence.update(selectedConfig);
        ConfigDashboardMBean configMBean = (ConfigDashboardMBean)SMSMailUtil.getAttributeInSessionMap(ConstantsOfSystem.CONFIGMBEAN);
        configMBean.searchConfig();
    }
}
